.class Lcom/noshufou/android/su/service/PermissionsDbService$PermissionsDbOpenHelper;
.super Landroid/database/sqlite/SQLiteOpenHelper;
.source "PermissionsDbService.java"


# annotations
.annotation system Ldalvik/annotation/EnclosingClass;
    value = Lcom/noshufou/android/su/service/PermissionsDbService;
.end annotation

.annotation system Ldalvik/annotation/InnerClass;
    accessFlags = 0x2
    name = "PermissionsDbOpenHelper"
.end annotation


# static fields
.field private static final DATABASE_NAME:Ljava/lang/String; = "permissions.sqlite"

.field private static final DATABASE_VERSION:I = 0x8

.field private static final LOG_BLOCK:Ljava/lang/String; = "CREATE TRIGGER IF NOT EXISTS log_block AFTER INSERT ON logs BEGIN DELETE FROM logs; END;"


# instance fields
.field final synthetic this$0:Lcom/noshufou/android/su/service/PermissionsDbService;


# direct methods
.method public constructor <init>(Lcom/noshufou/android/su/service/PermissionsDbService;Landroid/content/Context;)V
    .locals 3
    .parameter
    .parameter "context"

    .prologue
    .line 149
    iput-object p1, p0, Lcom/noshufou/android/su/service/PermissionsDbService$PermissionsDbOpenHelper;->this$0:Lcom/noshufou/android/su/service/PermissionsDbService;

    .line 150
    const-string v0, "permissions.sqlite"

    const/4 v1, 0x0

    const/16 v2, 0x8

    invoke-direct {p0, p2, v0, v1, v2}, Landroid/database/sqlite/SQLiteOpenHelper;-><init>(Landroid/content/Context;Ljava/lang/String;Landroid/database/sqlite/SQLiteDatabase$CursorFactory;I)V

    .line 151
    return-void
.end method

.method private makePrefs(Landroid/database/sqlite/SQLiteDatabase;)V
    .locals 3
    .parameter "db"

    .prologue
    .line 221
    const-string v1, "CREATE TABLE IF NOT EXISTS prefs (_id INTEGER PRIMARY KEY AUTOINCREMENT, key TEXT, value TEXT);"

    invoke-virtual {p1, v1}, Landroid/database/sqlite/SQLiteDatabase;->execSQL(Ljava/lang/String;)V

    .line 223
    new-instance v0, Landroid/content/ContentValues;

    invoke-direct {v0}, Landroid/content/ContentValues;-><init>()V

    .line 224
    .local v0, values:Landroid/content/ContentValues;
    const-string v1, "key"

    const-string v2, "notifications"

    invoke-virtual {v0, v1, v2}, Landroid/content/ContentValues;->put(Ljava/lang/String;Ljava/lang/String;)V

    .line 225
    const-string v1, "value"

    const-string v2, "1"

    invoke-virtual {v0, v1, v2}, Landroid/content/ContentValues;->put(Ljava/lang/String;Ljava/lang/String;)V

    .line 226
    const-string v1, "prefs"

    const/4 v2, 0x0

    invoke-virtual {p1, v1, v2, v0}, Landroid/database/sqlite/SQLiteDatabase;->insert(Ljava/lang/String;Ljava/lang/String;Landroid/content/ContentValues;)J

    .line 227
    return-void
.end method


# virtual methods
.method public onCreate(Landroid/database/sqlite/SQLiteDatabase;)V
    .locals 1
    .parameter "db"

    .prologue
    .line 155
    const-string v0, "CREATE TABLE IF NOT EXISTS apps (_id INTEGER PRIMARY KEY AUTOINCREMENT, uid INTEGER, package TEXT, name TEXT,  exec_uid INTEGER, exec_cmd TEXT, allow INTEGER, notifications INTEGER, logging INTEGER, dirty INTEGER, UNIQUE (uid,exec_uid,exec_cmd));"

    invoke-virtual {p1, v0}, Landroid/database/sqlite/SQLiteDatabase;->execSQL(Ljava/lang/String;)V

    .line 156
    const-string v0, "CREATE TABLE IF NOT EXISTS logs (_id INTEGER PRIMARY KEY AUTOINCREMENT, app_id INTEGER, date INTEGER, type INTEGER);"

    invoke-virtual {p1, v0}, Landroid/database/sqlite/SQLiteDatabase;->execSQL(Ljava/lang/String;)V

    .line 157
    const-string v0, "CREATE TRIGGER IF NOT EXISTS log_block AFTER INSERT ON logs BEGIN DELETE FROM logs; END;"

    invoke-virtual {p1, v0}, Landroid/database/sqlite/SQLiteDatabase;->execSQL(Ljava/lang/String;)V

    .line 158
    invoke-direct {p0, p1}, Lcom/noshufou/android/su/service/PermissionsDbService$PermissionsDbOpenHelper;->makePrefs(Landroid/database/sqlite/SQLiteDatabase;)V

    .line 159
    return-void
.end method

.method public onUpgrade(Landroid/database/sqlite/SQLiteDatabase;II)V
    .locals 16
    .parameter "db"
    .parameter "oldVersion"
    .parameter "newVersion"

    .prologue
    .line 164
    move/from16 v14, p2

    .line 172
    .local v14, upgradeVersion:I
    const/4 v1, 0x5

    if-ge v14, v1, :cond_1

    .line 179
    const-string v1, "DROP TABLE IF EXISTS apps;"

    move-object/from16 v0, p1

    invoke-virtual {v0, v1}, Landroid/database/sqlite/SQLiteDatabase;->execSQL(Ljava/lang/String;)V

    .line 180
    const-string v1, "DROP TABLE IF EXISTS logs;"

    move-object/from16 v0, p1

    invoke-virtual {v0, v1}, Landroid/database/sqlite/SQLiteDatabase;->execSQL(Ljava/lang/String;)V

    .line 181
    invoke-virtual/range {p0 .. p1}, Lcom/noshufou/android/su/service/PermissionsDbService$PermissionsDbOpenHelper;->onCreate(Landroid/database/sqlite/SQLiteDatabase;)V

    .line 218
    :cond_0
    :goto_0
    return-void

    .line 185
    :cond_1
    const/4 v1, 0x5

    if-ne v14, v1, :cond_2

    .line 187
    :try_start_0
    const-string v1, "ALTER TABLE apps ADD COLUMN notifications INTEGER"

    move-object/from16 v0, p1

    invoke-virtual {v0, v1}, Landroid/database/sqlite/SQLiteDatabase;->execSQL(Ljava/lang/String;)V

    .line 188
    const-string v1, "ALTER TABLE apps ADD COLUMN logging INTEGER"

    move-object/from16 v0, p1

    invoke-virtual {v0, v1}, Landroid/database/sqlite/SQLiteDatabase;->execSQL(Ljava/lang/String;)V
    :try_end_0
    .catch Landroid/database/sqlite/SQLiteException; {:try_start_0 .. :try_end_0} :catch_0

    .line 194
    :goto_1
    const/4 v14, 0x6

    .line 197
    :cond_2
    const/4 v1, 0x6

    if-ne v14, v1, :cond_3

    .line 198
    const-string v2, "apps"

    const/4 v1, 0x2

    new-array v3, v1, [Ljava/lang/String;

    const/4 v1, 0x0

    const-string v4, "_id"

    aput-object v4, v3, v1

    const/4 v1, 0x1

    const-string v4, "uid"

    aput-object v4, v3, v1

    .line 199
    const/4 v4, 0x0

    const/4 v5, 0x0

    const/4 v6, 0x0

    const/4 v7, 0x0

    const/4 v8, 0x0

    move-object/from16 v1, p1

    .line 198
    invoke-virtual/range {v1 .. v8}, Landroid/database/sqlite/SQLiteDatabase;->query(Ljava/lang/String;[Ljava/lang/String;Ljava/lang/String;[Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;)Landroid/database/Cursor;

    move-result-object v11

    .line 201
    .local v11, c:Landroid/database/Cursor;
    :goto_2
    invoke-interface {v11}, Landroid/database/Cursor;->moveToNext()Z

    move-result v1

    if-nez v1, :cond_4

    .line 210
    invoke-interface {v11}, Landroid/database/Cursor;->close()V

    .line 211
    const/4 v14, 0x7

    .line 214
    .end local v11           #c:Landroid/database/Cursor;
    :cond_3
    const/4 v1, 0x7

    if-ne v14, v1, :cond_0

    .line 215
    const-string v1, "CREATE TRIGGER IF NOT EXISTS log_block AFTER INSERT ON logs BEGIN DELETE FROM logs; END;"

    move-object/from16 v0, p1

    invoke-virtual {v0, v1}, Landroid/database/sqlite/SQLiteDatabase;->execSQL(Ljava/lang/String;)V

    .line 216
    invoke-direct/range {p0 .. p1}, Lcom/noshufou/android/su/service/PermissionsDbService$PermissionsDbOpenHelper;->makePrefs(Landroid/database/sqlite/SQLiteDatabase;)V

    goto :goto_0

    .line 189
    :catch_0
    move-exception v12

    .line 192
    .local v12, e:Landroid/database/sqlite/SQLiteException;
    const-string v1, "Su.PermissionsDbService"

    const-string v2, "notifications and logging columns already exist... wut?"

    invoke-static {v1, v2, v12}, Landroid/util/Log;->e(Ljava/lang/String;Ljava/lang/String;Ljava/lang/Throwable;)I

    goto :goto_1

    .line 202
    .end local v12           #e:Landroid/database/sqlite/SQLiteException;
    .restart local v11       #c:Landroid/database/Cursor;
    :cond_4
    const-string v1, "uid"

    invoke-interface {v11, v1}, Landroid/database/Cursor;->getColumnIndex(Ljava/lang/String;)I

    move-result v1

    invoke-interface {v11, v1}, Landroid/database/Cursor;->getInt(I)I

    move-result v13

    .line 203
    .local v13, uid:I
    const-string v1, "_id"

    invoke-interface {v11, v1}, Landroid/database/Cursor;->getColumnIndex(Ljava/lang/String;)I

    move-result v1

    invoke-interface {v11, v1}, Landroid/database/Cursor;->getLong(I)J

    move-result-wide v9

    .line 204
    .local v9, appId:J
    new-instance v15, Landroid/content/ContentValues;

    invoke-direct {v15}, Landroid/content/ContentValues;-><init>()V

    .line 205
    .local v15, values:Landroid/content/ContentValues;
    const-string v1, "name"

    move-object/from16 v0, p0

    iget-object v2, v0, Lcom/noshufou/android/su/service/PermissionsDbService$PermissionsDbOpenHelper;->this$0:Lcom/noshufou/android/su/service/PermissionsDbService;

    const/4 v3, 0x0

    invoke-static {v2, v13, v3}, Lcom/noshufou/android/su/util/Util;->getAppName(Landroid/content/Context;IZ)Ljava/lang/String;

    move-result-object v2

    invoke-virtual {v15, v1, v2}, Landroid/content/ContentValues;->put(Ljava/lang/String;Ljava/lang/String;)V

    .line 206
    const-string v1, "package"

    move-object/from16 v0, p0

    iget-object v2, v0, Lcom/noshufou/android/su/service/PermissionsDbService$PermissionsDbOpenHelper;->this$0:Lcom/noshufou/android/su/service/PermissionsDbService;

    invoke-static {v2, v13}, Lcom/noshufou/android/su/util/Util;->getAppPackage(Landroid/content/Context;I)Ljava/lang/String;

    move-result-object v2

    invoke-virtual {v15, v1, v2}, Landroid/content/ContentValues;->put(Ljava/lang/String;Ljava/lang/String;)V

    .line 207
    const-string v1, "apps"

    const-string v2, "_id=?"

    .line 208
    const/4 v3, 0x1

    new-array v3, v3, [Ljava/lang/String;

    const/4 v4, 0x0

    invoke-static {v9, v10}, Ljava/lang/String;->valueOf(J)Ljava/lang/String;

    move-result-object v5

    aput-object v5, v3, v4

    .line 207
    move-object/from16 v0, p1

    invoke-virtual {v0, v1, v15, v2, v3}, Landroid/database/sqlite/SQLiteDatabase;->update(Ljava/lang/String;Landroid/content/ContentValues;Ljava/lang/String;[Ljava/lang/String;)I

    goto :goto_2
.end method
